/*
 * ModificacionUsuario.java
 *
 * Created on 8 de marzo de 2007, 04:30 PM
 */

package everest3.usuarios;

import java.awt.event.ActionEvent; 
import javax.swing.JButton; 
import javax.swing.JDialog; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.JTextField;

/**
 * GUI que solicita el login y el password del usuario que se desea modificar
 * @author Julian Libreros Cardona
 */
public class ModificacionUsuario extends javax.swing.JDialog {
    
    everest3.usuarios.CuentasdeUsuario f;
    
    /**
     * Constructor de la clase ModificacionUsuario
     * @param parent Ventana en la cual se realiza la modificacion
     * @param modal Indica si el dialogo es modal
     */
    public ModificacionUsuario(everest3.usuarios.CuentasdeUsuario parent, boolean modal, String menu) {
        super(parent, modal); 
        this.menu = menu;
        f = parent;               
        f.setTitle("Cuentas Usuario - Modificar");
        initComponents();
         java.awt.Dimension pantalla, cuadro;
		pantalla = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
		cuadro = this.getSize();				
		
		this.setLocation(((pantalla.width - cuadro.width)/2), 
						(pantalla.height - cuadro.height)/2);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        campoLogin = new javax.swing.JTextField();
        botonAceptar = new javax.swing.JButton();
        botonCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Ingrese su nick");
        setModal(true);
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Ingresar nick"));
        jLabel1.setText("Nick");

        campoLogin.setDocument(new everest3.utils.LimitadorCaracteres(campoLogin,12,2));
        campoLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(23, 23, 23)
                .addComponent(campoLogin, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(campoLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        botonAceptar.setText("Aceptar");
        botonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAceptarActionPerformed(evt);
            }
        });

        botonCancelar.setText("Cancelar");
        botonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(78, 78, 78)
                .addComponent(botonAceptar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(78, 78, 78))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonAceptar)
                    .addComponent(botonCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * 
     * @param evt 
     */
    /**
     * 
     * @param evt 
     */
    private void botonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCancelarActionPerformed
        dispose();
        if(menu.equals("M"))
        {
            f.cerrar();
        }
    }//GEN-LAST:event_botonCancelarActionPerformed

    /**
     * 
     * @param evt 
     */
    private void botonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAceptarActionPerformed
        consultar();
    }//GEN-LAST:event_botonAceptarActionPerformed
    
    private void consultar()
    {
        if(validarCamposVacios())
            javax.swing.JOptionPane.showMessageDialog(this,
                                        "Ninguno de los campos debe quedar vac\u00edo",
                                        "Error",javax.swing.JOptionPane.WARNING_MESSAGE);
        
        else
        {
            java.util.Vector resultadoConsulta = everest3.usuarios.CuentaUsuario.consultarUsuario(campoLogin.getText(),null);
            if (resultadoConsulta.isEmpty())
                  javax.swing.JOptionPane.showMessageDialog(f,
                                        "Error al intentar modificar el usuario.\n"+                                       
                                        "El usuario no existe\n",
                                        "Error",javax.swing.JOptionPane.WARNING_MESSAGE);
            
            else
            {
                dispose();
                f.establecerCampos(resultadoConsulta);
                f.setVisible(true);                                
            }
        }
    }
    /**
     * 
     * @return 
     */
    private boolean validarCamposVacios()
    {
        return(campoLogin.getText().length()==0);
    }
    
    /**
     * @param args the command line arguments
     */
   /* public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ModificacionUsuario(new javax.swing.JFrame(), true).setVisible(true);
            }
        });
    }*/
   private String menu;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAceptar;
    private javax.swing.JButton botonCancelar;
    private javax.swing.JTextField campoLogin;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
    
}
